// pages/defect/craft/params-options/index.js
import {
  _update
} from '../../../../../api/recipe-Import-method'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    dataSource: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    showModal: false,
    data: {}
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onClose() {
      this.setData({
        show: false
      });
    },
    onDelect() {
      wx.showModal({
        title: '是否要删除此引入方式？',
        success: res => {
          if (res.confirm) {
            _remove(this.data.data, () => {
              this.triggerEvent('update')
            })
          }
        }
      })
    },
    open({
      maxNumber,
      minNumber,
      name,
      ingredientsId,
      id,
      recipeCompositionTypeId
    }) {
      const instance = this.selectComponent('#params');
      instance?.initData({
        form: {
          max: maxNumber,
          min: minNumber,
          id,
          val: {
            id: ingredientsId,
            name
          }
        }
      })
      this.setData({
        data: {
          id,
          recipeCompositionTypeId
        }
      })
      this.onModalShow();
    },
    onModalCancel() {
      this.setData({
        showModal: false
      })
    },
    onModalShow() {
      this.setData({
        showModal: true
      })
    },
    onModalSubmit(event) {
      _update({
        ...event.detail,
        id: this.data.data['id'],
        recipeCompositionTypeId: this.data.data['recipeCompositionTypeId']
      }, () => {
        this.triggerEvent('update');
        this.onModalCancel();
      })
    }
  }
})